package com.iflytek.uoamp.notify.msg.format;

import java.util.List;

import com.iflytek.uoamp.common.notify.enumerate.State;
import com.iflytek.uoamp.common.notify.obj.Content;
import com.iflytek.uoamp.common.notify.obj.Notification;
import com.iflytek.uoamp.common.notify.util.NotifyUtils;

public class FormatCommonMsg extends FixedMsgFormatter {
	
    private static final String COMMON = "监控项";

    @Override
    public String pretty(Notification notification, List<?> contents) {
        Content content = (Content) contents.get(0);
        StringBuilder builder = new StringBuilder(TEMPLATE_ID + "@@");
        builder.append("{\"monitortime\":\"");
        builder.append(content.getMonitorTime());
        
        builder.append("\",\"monitortype\":\"");
        builder.append(COMMON);
        
        builder.append("\",\"monitorname\":\"");
        builder.append(getTitle(contents));
        
        builder.append("\",\"state\":\"");
        builder.append(State.getName(content.getState()));
        
        builder.append("\",\"statedes\":\"");
        builder.append(NotifyUtils.getAttributeValue(content.getOutput(),
                "statedes"));
        builder.append("\"}");
        
        return builder.toString();
    }
    
    public String getTitle(List<?> contents) {
        Content content = (Content)contents.get(0);
        String output = content.getOutput();
        
        return NotifyUtils.getAttributeValue(output, "subject");
    }
    
}
